define([ "jquery","comm","site_tip","dialog"], function($,comm,Site_tip,Dialog) {
	
	//require(['plugin/jquery.ajax.ext'],function(){});
	var site_tip = new Site_tip();
	function Ctrl_policies(status,file_id,folder){
		this.status = status;
		this.file_id = file_id;
		//0:文件  1：文件夹
		this.type = 0;
		this.item = null;
		this.alertPolicy = true;
		this.folder=folder;
	}

	Ctrl_policies.prototype.openBatch = function(files,folders,cb,content,title,btnText)
	{
		var that= this;
		files = files||[];
		folders = folders||[];
		var obj = {};
		obj.open = true;
		obj.title = title||"访问控制";
		obj.content = content||"受控文件已被禁止访问，将被开启访问";
		obj.btn_text = btnText||"允许访问";

		var dialog = new Dialog(obj, function(fid,dialogObj){
			$.post("/files/update_access_denied",{files:files,folders:folders}, function(data) {
				//dialogObj.close();
				if (data.success) {
					if(files.length>0){
						$.each(files,function(k,v){
							var row = $("#waterfall").find("[name=uuid][value='"+v+"']").parent();
							row.attr("isforbin","0");
							row.removeClass("forbin");
							var pLock = row.find(".policy-lock");
							pLock.attr("title","允许访问");
							var slider = pLock.find(".slider");
							var policy_sta = pLock.find(".policy_sta");
							policy_sta.addClass("hover");
							slider.animate({left:'26px'});
						});
					}
					if($("#wfo").data("detail") == 1 && that.folder)
					{
						that.folder.showDetail();
					}
					/*$("#glable_mask").remove();
					 $("#dialog_shade").remove();*/
					if($.isFunction(cb))
					{
						cb();
					}
				} else {
					site_tip.setContent(data.message,true,false);
					if(data.error_code==7100 || data.error_code==7001)
					{
						require(["folder/main"],function(Folder){
							new Folder().reload();
						});
					}
				}
			}, 'json');
		});
		dialog.init();
		return false;
	}

	Ctrl_policies.prototype.init = function(tdata,cb){
		if(this.status == 0){
			this.close(cb);
			return;
		}
		
		this.open(cb);
	}
	
	Ctrl_policies.prototype.open = function(cb){
		var that = this;
		function set_open(file_id,dialog){
			var params={denied:0};
			if(that.type==1)
			{
				params.folders = file_id;
			}
			else
			{
				params.files = file_id;
			}
			$.post("/files/update_access_denied",params, function(data) {
				//dialog.close();
				if (data.success) {
					if(that.item != null){
						that.item.attr("isforbin","0");
						that.item.removeClass("forbin");
						
						var pLock = that.item.find(".policy-lock");
						pLock.attr("title","允许访问");
						var slider = pLock.find(".slider");
						var policy_sta = pLock.find(".policy_sta");
						policy_sta.addClass("hover");
						slider.animate({left:'26px'});
						
					}
					if($("#wfo").data("detail") == 1 && that.folder)
					{
						that.folder.showDetail();
					}
					/*$("#glable_mask").remove();
					$("#dialog_shade").remove();*/
					if($.isFunction(cb))
					{
						cb();
					}
				} else {
					site_tip.setContent(data.message,true,false);
					if(data.error_code==7100 || data.error_code==7001)
					{
						require(["folder/main"],function(Folder){
							new Folder().reload();
						});
					}
				}
			}, 'json');

		};
		
		var obj = new Object();
		obj.open = true;
		obj.title = "访问控制";
		obj.content = "受控文件已被禁止访问，将被开启访问";
		obj.btn_text = "允许访问";
		obj.file_id = that.file_id;

		var dialog = new Dialog(obj, set_open);
		dialog.init();
		return false;
	}
	
	Ctrl_policies.prototype.close = function(cb){
		var that = this;
		function set_close(file_id,dialog){
			var params={denied:1};
			if(that.type==1)
			{
				params.folders = file_id;
			}
			else
			{
				params.files = file_id;
			}
			$.post("/files/update_access_denied",params, function(data) {
				//dialog.close();
				//$("#site-tip").stop();
				if (data.success) {
					// alert("禁止成功");
					if(that.item != null){
						that.item.attr("isforbin","1");
						that.item.addClass("forbin");
						
						var pLock = that.item.find(".policy-lock");
						pLock.attr("title","禁止访问");
						var slider = pLock.find(".slider");
						var policy_sta = pLock.find(".policy_sta");
						policy_sta.removeClass("hover");
						slider.animate({left:'11px'});
						
					}
					site_tip.setContent("已禁止",false,false);
					
					/*$("#glable_mask").remove();
					$("#dialog_shade").remove();*/
					
					if($("#wfo").data("detail") == 1 && that.folder){
						that.folder.showDetail();
					}
					if($.isFunction(cb))
					{
						cb();
					}
				} else {
					site_tip.setContent(data.message,true,false);
					if(data.error_code==7100 || data.error_code==7001)
					{
						require(["folder/main"],function(Folder){
							new Folder().reload();
						});
					}
				}

			}, 'json');
		}
		

		var obj = new Object();
		obj.content = "该受控文件将不能被下载和查阅";
		obj.title = "访问控制";
		obj.file_id = that.file_id;

		var dialog = new Dialog(obj, set_close);
		dialog.init();
		return false;
	}
	
	return Ctrl_policies;
	
});